//状态管理
import 'package:flutter/cupertino.dart';
import 'package:hive_storage/data/settings_repository.dart';
import 'package:hive_storage/models/settings_model.dart';
class SettingsViewmodel extends ChangeNotifier{
  final SettingsRepository _repository;
  SettingsModel _settings;

  SettingsViewmodel(this._repository ,SettingsModel initialSettings)
  :_settings = initialSettings;
  SettingsModel get settings =>_settings;

  Future<void> localSettings() async{
    _settings = await _repository.getSettings();
    notifyListeners();
  }

  Future<void> updateSettings(SettingsModel newSettings) async{
    _settings= newSettings;
    await _repository.saveSettings(newSettings);
    notifyListeners();
  }
}